// ml:run = $bin < input
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <vector>

int const maxn = 37000;
int const maxk = 55;
int const inf = 1 << 29;
int f[maxn][maxk];
int s[maxn][maxk];
// int a[maxn];
int n, m;
int mark[maxn];

std::vector<int> a;

int main()
{
    scanf("%d%d", &n, &m);
    a.resize(n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (int i = 0; i <= n + 1; i++)
        for (int j = 0; j <= m + 1; j++) f[i][j] = -1;

    int op = 1;
    f[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        int ti = std::min(i, m);
        s[i][ti + 1] = i - 1;
        f[i][0] = 0;
        for (int j = ti; j >= 1; j--) {
            int now = 0;
            std::unordered_set<int> us(a.begin() + s[i][j + 1] + 1, a.begin() + i + 1);
            now = us.size();
            // for (int k = s[i][j + 1] + 1; k <= i; k++) {
            //     if (mark[a[k]] != op) now++;
            //     mark[a[k]] = op;
            // }
            for (int k = s[i][j + 1]; k >= s[i - 1][j]; k--) {
                int t = f[k][j - 1] + now;
                if (t > f[i][j]) {
                    f[i][j] = t;
                    s[i][j] = k;
                }
                if (mark[a[k]] != op) now++;
                mark[a[k]] = op;
            }
            op++;
        }
    }
    printf("%d\n", f[n][m]);
}

